<?php
namespace Home\Controller;
use Think\Controller;
use Think\Model;
use Overtrue\Wechat\Js;
class IndexController extends Controller {
    public function index(){
        if(IS_POST){
            session("username",$_POST['corpsname']);
            redirect(U('Information')."?channel=".$_GET['channel']);
        }
        $wechat = C('wechat');
        $jsapi = new Js($wechat['app'], $wechat['secret'] );
        $api = array('onMenuShareTimeline', 'onMenuShareAppMessage','onMenuShareQZone','onMenuShareQQ','onMenuShareWeibo');
        $this->assign('js',$jsapi->config($api,false));
        $this->display();
    }
    //“组团啦”杯LOL比赛须知
    public function Information($channel=''){
        $this->assign("channel",$channel);
        $wechat = C('wechat');
        $jsapi = new Js($wechat['app'], $wechat['secret'] );
        $api = array('onMenuShareTimeline', 'onMenuShareAppMessage','onMenuShareQZone','onMenuShareQQ','onMenuShareWeibo');
        $this->assign('js',$jsapi->config($api,false));
        $this->display();
    }
    //“组团啦”杯战队报名
    public function Team_information(){
        if(IS_POST){
            $Corps = D('Corps');
            $data['headername'] = $_POST['headername'];
            $data['idcard'] = $_POST['idcard'];
            $data['email'] = $_POST['email'];
            $data['telephone'] = $_POST['telephone'];
            $data['qqnumber'] = $_POST['qqnumber'];
            $data['school'] = $_POST['school'];
            $data['corpsnumber'] = $_POST['corpsnumber'];
            $data['remarks'] = $_POST['remarks'];
            $data['channel']=$_POST['channel'];
            $data['corpsname']=session("username");
            $info = $Corps->add($data);
            $Corps->save(array(
                'id' =>$info,
                'corpsnumber' =>"LOL".$info,
            ));
            session("is_report",'您的战队编号是：LOL'.$info);
            session("id",$info);
            if($info){
                $this->success($info);
            }else{
                $this->error('');
            }
        }
        if(!empty(session("id"))){
            $data = D('Corps')->where("id=".session("id"))->find();
            $this->assign("name",$data);
        }
        $this->assign('corpsname',session("username"));
        $wechat = C('wechat');
        $jsapi = new Js($wechat['app'], $wechat['secret'] );
        $api = array('onMenuShareTimeline', 'onMenuShareAppMessage','onMenuShareQZone','onMenuShareQQ','onMenuShareWeibo');
        $this->assign('js',$jsapi->config($api,false));
        $this->display();
    }
    //关注“组团啦”官方帐号、
    public function Join_us(){
        $wechat = C('wechat');
        $jsapi = new Js($wechat['app'], $wechat['secret'] );
        $api = array('onMenuShareTimeline', 'onMenuShareAppMessage','onMenuShareQZone','onMenuShareQQ','onMenuShareWeibo');
        $this->assign('js',$jsapi->config($api,false));
        $this->display();
    }
}